<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
  <title>魔售商城|MoreShow</title>
  <style>
    #tip {
      text-align: center;
    }
  </style>
</head>
<body>
  <h3 id="tip"></h3>
  <script>
    var tip = document.getElementById('tip');

    function redirectToApp() {
      var query = window.location.search;
      var product_id = query.split('?product_id=').pop();
      if (! product_id) {
        return alert('错误的 App 跳转参数');
      }

      if (isIOS()) {
        var url = 'ZZYDireWolf://moreshow-product?id=' + product_id;
      } else if (isAndroid()) {
        var url = 'moreshow://dw-api.panxsoft.com/product?id=' + product_id;
      } else {
        return alert('platform detect error, please check UA:' + navigator.userAgent);
      }

      var a = document.createElement('a');
      a.href = url;
      a.click();
    }

    function redirectDownloadApp() {
      if (isBaidu()) {
        tip.innerText = '百度浏览器禁止应用跳转，请复制当前网址链接并在其他浏览器中打开';
        return;
      }

      // 微信中增加文字提示
      if (isWechat()) {
        if (isIOS()) {
          tip.innerText = '请点击右上角菜单并选择"在Safari中打开"';
        }  else {
          tip.innerText = '请点击右上角菜单并选择"在浏览器中打开"';
        }
        return;
      }

      // 正常可跳转的浏览器
      if (isIOS()) {
        location.href = 'https://itunes.apple.com/cn/app/%E9%AD%94%E5%94%AE%E5%95%86%E5%9F%8E/id1448964298?mt=8';
      } else if (isAndroid()) {
        location.href  = 'https://www.pgyer.com/rqDw';
      } else {
        alert('Not iOS or Android, Please check your platform');
      }
    }

    function isIOS() {
      return /iPhone|iPad/i.test(navigator.userAgent);
    }

    function isAndroid() {
      return /Android/i.test(navigator.userAgent);
    }

    function isWechat() {
      return /MicroMessenger/i.test(navigator.userAgent);
    }

    function isBaidu() {
      return /baidu/i.test(navigator.userAgent);
    }

    redirectToApp();
    redirectDownloadApp()
  </script>
</body>
</html>